﻿using System;
using System.Collections;
using System.Diagnostics;
using Rhizome.Contract;

namespace Rhizome.Model
{
    public sealed class DelegateActiveObject : ActiveObjectBase
    {
        #region IActiveObject Members

        /// <summary>
        ///   Sets the subroutine for ActiveObject.
        /// </summary>
        /// <value>The subroutine.</value>
        private readonly IEnumerator _coroutine;

        #endregion

        #region ctors

        [DebuggerStepThrough]
        public DelegateActiveObject(IActiveObjectHost host, IEnumerator coroutine) : base(host)
        {
            if (coroutine == null) throw new ArgumentNullException("coroutine");
            _coroutine = coroutine;
        }

        #endregion

        #region implementation

        #endregion

        public override void Step()
        {
            if (_coroutine.MoveNext() == false)
                Active = false;
        }
    }
}